package pers.cz.config;

import pers.cz.mybatis.page.PagePlugin;
import pers.cz.mybatis.shard.ShardingPlugin;
import pers.cz.mybatis.slowsql.SlowSqlPlugin;
import pers.cz.properties.MyBatisProperties;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

/**
 * myBatis配置类(主要用于配置mybatis插件)
 * @program: PostGirl-panent
 * @description: MyBatisConfig
 * @author: Cheng Zhi
 * @create: 2021-03-12 18:54
 **/
@org.springframework.context.annotation.Configuration
@MapperScan({"pers.cz.mybatis.page"})
public class MyBatisConfig {

    @Autowired
    MyBatisProperties properties;

    private static String time;
    //注册插件

    /**
     * 分页插件
     * @return
     */
    @Bean
    public PagePlugin pagePlugin() {

        PagePlugin PagePlugin = new PagePlugin();
        //Properties properties = new Properties();
        PagePlugin.setProperties(properties);

        return PagePlugin;
    }

    /**
     * 慢sql兜取
     * @return
     */
    @Bean
    public SlowSqlPlugin slowSqlPlugin() {

        SlowSqlPlugin slowSqlPlugin = new SlowSqlPlugin();
        //Properties propertiesNew = new Properties();
        //propertiesNew.setProperty("time",properties.getTime()); // 后续修改配读取配置文件
        //slowSqlPlugin.setProperties(propertiesNew);
        slowSqlPlugin.setProperties(properties);

        return slowSqlPlugin;
    }

    /**
     * 分表插件  由于分表后分页查询的问题没有得到解决，所以暂时不进行分表
     * @return
     */
/*    @Bean
    public ShardingPlugin shardingPlugin() {

        ShardingPlugin shardingPlugin = new ShardingPlugin();
        shardingPlugin.setProperties(properties);
        return  shardingPlugin;
    }*/
}
